package com.example.sociamedia.post.mapper;

import com.example.sociamedia.post.entity.Like;
import org.apache.ibatis.annotations.*;
import java.util.List;

@Mapper
public interface LikeMapper {
    @Insert("INSERT INTO likes (PostId, UserId, CreatedAt) VALUES (#{postId}, #{userId}, NOW())")
    @Options(useGeneratedKeys = true, keyProperty = "likeId", keyColumn = "LikeId")
    int insertLike(Like like);

    @Delete("DELETE FROM likes WHERE PostId = #{postId} AND UserId = #{userId}")
    int deleteLike(@Param("postId") Long postId, @Param("userId") Long userId);

    @Select("SELECT * FROM likes WHERE PostId = #{postId} AND UserId = #{userId}")
    Like selectLike(@Param("postId") Long postId, @Param("userId") Long userId);

    @Select("SELECT COUNT(*) FROM likes WHERE PostId = #{postId}")
    int countLikesByPost(@Param("postId") Long postId);

    @Select("SELECT * FROM likes WHERE PostId = #{postId}")
    List<Like> selectLikesByPost(@Param("postId") Long postId);

    @Select("SELECT * FROM likes WHERE UserId = #{userId}")
    List<Like> selectLikesByUser(@Param("userId") Long userId);
} 